package com.webcash.CNBoard.Controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.webcash.CNBoard.Model.CalendarModel;
import com.webcash.CNBoard.Model.Department;
import com.webcash.CNBoard.Model.Employee;
import com.webcash.CNBoard.Model.Login;
import com.webcash.CNBoard.Model.MyProject;
import com.webcash.CNBoard.Model.PositionName;
import com.webcash.CNBoard.Model.Project;
import com.webcash.CNBoard.Model.ProjectFile;
import com.webcash.CNBoard.Model.Work;
import com.webcash.CNBoard.Service.DepartmentService;
import com.webcash.CNBoard.Service.EmployeeService;
import com.webcash.CNBoard.Service.PositionNameService;
import com.webcash.CNBoard.Service.PrintOutService;
import com.webcash.CNBoard.Service.ProjectFileService;
import com.webcash.CNBoard.Service.ProjectService;
import com.webcash.CNBoard.util.CalendarUtil;

@Controller
@RequestMapping("/project/printOut")
@SessionAttributes("login")
public class ProjectPrintOutController {
	@Autowired
	EmployeeService employeeService;
	@Autowired
	DepartmentService departmentService;
	@Autowired
	PositionNameService positionNameService;
	@Autowired
	ProjectService projectService;
	@Autowired
	PrintOutService printOutService;
	@Autowired
	MyProject myProject;
	@Autowired
	ProjectFileService projectFileService;
	
	@RequestMapping
	public String action(@ModelAttribute Login login, Model model){
		Employee emp=employeeService.getEmployeeById(login.getId());
		Department dept=departmentService.getDepartmentByDeptNo(Integer
				.parseInt(emp.getDeptNo()));
		PositionName emppos = positionNameService.getPositionNamebyPositionNo(Integer.parseInt(emp.getPosition()));
		Project project = projectService.getProjectByProjectNo(myProject.getProjectNo());
		List<Work> workList = projectService.getWorkListByProjectNoAndId(myProject.getProjectNo(),login.getId());
		
		CalendarUtil calendarUtil = new CalendarUtil();
		CalendarModel cal = calendarUtil.calendar();
		
		List<ProjectFile> projectfilelist = projectFileService.getProjectFileList(myProject.getProjectNo());
		
		model.addAttribute("ProjectFileList", projectfilelist);
		model.addAttribute("dept", dept);
		model.addAttribute("emp", emp);
		model.addAttribute("emppos", emppos);
		model.addAttribute("project",project);
		model.addAttribute("workList", workList);
		model.addAttribute("cal", cal);
		
		return "printout/printOut";
	}
	
	@RequestMapping(value="/print")
	public String print(){
		return "printout/black_print";
	}
}
